/**
 * 
 */
package com.nari.interfaces.decipher.pda;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.Element;

import com.nari.heatshare.model.IAssignMeterDataGather;
import com.nari.heatshare.model.ITemperaturePointDataGather;
import com.nari.interfaces.decipher.common.HeatMeterDataProtocolDecipher;
import com.nari.interfaces.decipher.common.MeasureUnitConstants;
import com.nari.interfaces.decipher.common.warn.DecipherWarnConstants;
import com.nari.interfaces.decipher.common.warn.DecipherWarnLogger;
import com.nari.interfaces.decipher.gprs.FrameEntityConstants;
import com.nari.interfaces.decipher.gprs.vo.UploadMeterDataSeal;
import com.nari.interfaces.model.IHeatMeterData24Gather;
import com.nari.interfaces.model.IMissionFailureLog;
import com.nari.platform.date.CalendarUtils;
import com.nari.platform.parser.xmlparser.Dom4jXmlReader;
import com.nari.platform.utils.StringUtils;
import com.sohoometer.utils.ParseUtils;

/**
 * 掌机上传数据解码器
 * @author Xiaopeng
 * @date 2013-11-14
 */
public class PdaUploadSeal {
	
	/**
	 * 解析掌机上传数据文件
	 * @param xmlPath
	 * @return
	 * @throws Exception
	 * @author Xiaopeng
	 * @date 2013-11-14
	 */
	public synchronized static UploadMeterDataSeal parsePdaUpload(String xmlPath) throws Exception {
		UploadMeterDataSeal pdaMeterDataSeal = null;
		//加载掌机数据文件
		Document xmlDoc = Dom4jXmlReader.loadXml(xmlPath);
		if(xmlDoc != null) {
			pdaMeterDataSeal = new UploadMeterDataSeal();
			//读取根节点
			Element rootElement = Dom4jXmlReader.getRootElement(xmlDoc);
			//读取集中器节点
			Element concentratorElement = Dom4jXmlReader.getChildElementByTagName(rootElement, "Concentrator");
			//集中器号
			String concentratorNo = Dom4jXmlReader.getChildElementTextByTagName(concentratorElement, "id");
			pdaMeterDataSeal.setConcentratorNo(concentratorNo);
			//解析热表数据
			List<Element> distributorElements = Dom4jXmlReader.getChildrenElementsByTagName(concentratorElement, "distributor");
			for(Iterator<Element> it=distributorElements.iterator(); it.hasNext();) {
				Element distributorElement = it.next();
				//根据id识别位判断分配表数据或热量表数据
				String meterDataDistinguishStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "id");
				//日志记录
				if(!StringUtils.isFullNumbericChar(meterDataDistinguishStr)) {
					//异常审计
					String auditLog = "无法解析的热表标识位【"+meterDataDistinguishStr+"】";
					IMissionFailureLog logger = DecipherWarnLogger.getMissionLogInstance(DecipherWarnConstants.logger_meterType_pda, 
							pdaMeterDataSeal.getConcentratorNo(), pdaMeterDataSeal.getRecordTime(), auditLog, null);
					pdaMeterDataSeal.getFrameDecoderLogList().add(logger);
					continue;
				}
				int meterDataDistinguish = Integer.valueOf(meterDataDistinguishStr);
				if(meterDataDistinguish <= FrameEntityConstants.received_distinguishCode_assignMeterSerial_max) {
					//分配表数据
					IAssignMeterDataGather meterData = parseAssignMeterData(distributorElement);
					pdaMeterDataSeal.getAssignMeterDatas().add(meterData);
				} else if(meterDataDistinguish >= FrameEntityConstants.received_distinguishCode_tempPointSerial_min 
						&& meterDataDistinguish <= FrameEntityConstants.received_distinguishCode_tempPointSerial_max) {
					//温度点数据，协议未定  //查看如何上传
					ITemperaturePointDataGather temperaturePointData = parseTemperaturePointData(distributorElement, concentratorNo);
					pdaMeterDataSeal.getTempPointDatas().add(temperaturePointData);
				} else if(meterDataDistinguish >= FrameEntityConstants.received_distinguishCode_heatMeter_min) {
					//热量表数据
					IHeatMeterData24Gather meterData = parseHeatMeterData(distributorElement);
					pdaMeterDataSeal.getHeatMeterDatas().add(meterData);
				}
			}
			//设置抄表日期 - 取掌机数据中抄表日期的最大值(暂未考虑掌机数据中不同热表的抄表日期比较)
			String recordTime = null;
			if(pdaMeterDataSeal.getAssignMeterDatas().size() > 0) {
				Collections.sort(pdaMeterDataSeal.getAssignMeterDatas(), new Comparator<IAssignMeterDataGather>() {
					public int compare(IAssignMeterDataGather o1, IAssignMeterDataGather o2) {
						//抄表日期逆序排序
						return CalendarUtils.compare(o2.getRecordTime(), o1.getRecordTime());
					}
				});
				recordTime = CalendarUtils.parseDateToString(pdaMeterDataSeal.getAssignMeterDatas().get(0).getRecordTime());
			} else if(pdaMeterDataSeal.getTempPointDatas().size() > 0) {
				Collections.sort(pdaMeterDataSeal.getTempPointDatas(), new Comparator<ITemperaturePointDataGather>() {
					public int compare(ITemperaturePointDataGather o1, ITemperaturePointDataGather o2) {
						//抄表日期逆序排序
						return CalendarUtils.compare(o2.getRecordTime(), o1.getRecordTime());
					}
				});
				recordTime = CalendarUtils.parseDateToString(pdaMeterDataSeal.getTempPointDatas().get(0).getRecordTime());
			} else if(pdaMeterDataSeal.getHeatMeterDatas().size() > 0) {
				Collections.sort(pdaMeterDataSeal.getHeatMeterDatas(), new Comparator<IHeatMeterData24Gather>() {
					public int compare(IHeatMeterData24Gather o1, IHeatMeterData24Gather o2) {
						//抄表日期逆序排序
						return CalendarUtils.compare(o2.getRecordTime(), o1.getRecordTime());
					}
				});
				recordTime = CalendarUtils.parseDateToString(pdaMeterDataSeal.getHeatMeterDatas().get(0).getRecordTime());
			}
			pdaMeterDataSeal.setRecordTime(recordTime);
			//设置热量表数据的集中器标识，方便后台识别热表数据记录数
			if(pdaMeterDataSeal.getHeatMeterDatas().size() > 0) {
				pdaMeterDataSeal.setConcentratorNo("manualUploadXML_hmd_"+pdaMeterDataSeal.getHeatMeterDatas().size()+"_records");
			}
		}
		return pdaMeterDataSeal;
	}
	
	/**
	 * 将XML数据节点解码为对应的分配表数据
	 * @param distributorElements
	 * @return
	 * @author Xiaopeng
	 * @throws ParseException 
	 * @date 2013-11-14
	 */
	private static IAssignMeterDataGather parseAssignMeterData(Element distributorElement) throws ParseException {
		IAssignMeterDataGather meterData = new IAssignMeterDataGather();
		//数据是否需要修正
		boolean ifDataRevised = false;
		//分配表序号
		String seriousNum = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "id");
		//集中器号
		String concentratorNo = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "addr");
		meterData.setConcentratorNo(concentratorNo);
		//分配表号，分配表号 = 集中器号 + 分配表序号
		seriousNum = concentratorNo + seriousNum;
		meterData.setSeriousNum(seriousNum);
		//前板温度
		String fontTemperatureStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "frTmp");
		double fontTemperature = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(fontTemperatureStr)) {
			fontTemperature = new Double(fontTemperatureStr);
		} else {
			fontTemperature = new Double(FrameEntityConstants.sysrevisable_am_fontTemperature_val);
			ifDataRevised = true;
		}
		meterData.setFontTemperature(fontTemperature);
		//背板温度
		String backTmperatureStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "bkTmp");
		double backTmperature = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(backTmperatureStr)) {
			backTmperature = new Double(backTmperatureStr);
		} else {
			backTmperature = new Double(FrameEntityConstants.sysrevisable_am_backTmperature_val);
			ifDataRevised = true;
		}
		meterData.setBackTmperature(backTmperature);
		//热量表当前读数
		String readNumStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "curHot");
		double readNum = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(readNumStr)) {
			readNum = new Double(readNumStr);
		} else {
			readNum = new Double(FrameEntityConstants.sysrevisable_am_readNum_val);
			ifDataRevised = true;
		}
		meterData.setReadNum(readNum);
		//上传时间
		String readTimeStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "UpdateTime");
		Date readTime = null;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(readTimeStr)) {
			readTime = CalendarUtils.parseStringToDate(readTimeStr, "yyMMddHHmmss");
		} else {
			readTime = CalendarUtils.parseStringToDate(FrameEntityConstants.sysrevisable_am_readTime_val, "yyMMddHHmmss");
			ifDataRevised = true;
		}
		meterData.setReadTime(readTime);
		//1月热量
		String oneHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m1");
		double oneHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(oneHeatStr)) {
			oneHeat = new Double(oneHeatStr);
		} else {
			oneHeat = new Double(FrameEntityConstants.sysrevisable_am_oneHeat_val);
			ifDataRevised = true;
		}
		meterData.setOneHeat(oneHeat);
		//2月热量
		String twoHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m2");
		double twoHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(twoHeatStr)) {
			twoHeat = new Double(twoHeatStr);
		} else {
			twoHeat = new Double(FrameEntityConstants.sysrevisable_am_twoHeat_val);
			ifDataRevised = true;
		}
		meterData.setTwoHeat(twoHeat);
		//3月热量
		String threeHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m3");
		double threeHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(threeHeatStr)) {
			threeHeat = new Double(threeHeatStr);
		} else {
			threeHeat = new Double(FrameEntityConstants.sysrevisable_am_threeHeat_val);
			ifDataRevised = true;
		}
		meterData.setThreeHeat(threeHeat);
		//4月热量
		String fourHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m4");
		double fourHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(fourHeatStr)) {
			fourHeat = new Double(fourHeatStr);
		} else {
			fourHeat = new Double(FrameEntityConstants.sysrevisable_am_fourHeat_val);
			ifDataRevised = true;
		}
		meterData.setFourHeat(fourHeat);
		//5月热量
		String fiveHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m5");
		double fiveHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(fiveHeatStr)) {
			fiveHeat = new Double(fiveHeatStr);
		} else {
			fiveHeat = new Double(FrameEntityConstants.sysrevisable_am_fiveHeat_val);
			ifDataRevised = true;
		}
		meterData.setFiveHeat(fiveHeat);
		//10月热量
		String tenHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m10");
		double tenHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(tenHeatStr)) {
			tenHeat = new Double(tenHeatStr);
		} else {
			tenHeat = new Double(FrameEntityConstants.sysrevisable_am_tenHeat_val);
			ifDataRevised = true;
		}
		meterData.setTenHeat(tenHeat);
		//11月热量
		String elevenHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m11");
		double elevenHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(elevenHeatStr)) {
			elevenHeat = new Double(elevenHeatStr);
		} else{
			elevenHeat = new Double(FrameEntityConstants.sysrevisable_am_elevenHeat_val);
			ifDataRevised = true;
		}
		meterData.setElevenHeat(elevenHeat);
		//12月热量
		String twelveHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "m12");
		double twelveHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(twelveHeatStr)) {
			twelveHeat = new Double(twelveHeatStr);
		} else {
			twelveHeat = new Double(FrameEntityConstants.sysrevisable_am_twelveHeat_val);
			ifDataRevised = true;
		}
		meterData.setTwelveHeat(twelveHeat);
		//去年热量
		String lastYearHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "lastYear");
		double lastYearHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(lastYearHeatStr)) {
			lastYearHeat = new Double(lastYearHeatStr);
		} else {
			lastYearHeat = new Double(FrameEntityConstants.sysrevisable_am_lastYearHeat_val);
			ifDataRevised = true;
		}
		meterData.setLastYearHeat(lastYearHeat);
		//抄表时间
		String recordTimeStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "sendTime");
		Date recordTime = null;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(recordTimeStr)) {
			recordTime = CalendarUtils.parseStringToDate(recordTimeStr, "yyMMddHHmmss");
		} else {
			recordTime = CalendarUtils.parseStringToDate(FrameEntityConstants.sysrevisable_am_recordTime_val, "yyMMddHHmmss");
			ifDataRevised = true;
		}
		meterData.setRecordTime(recordTime);
		//设置数据类型：掌机上传数据
		meterData.setDataType(3);
		//热表数据抄收状态
		if(ifDataRevised) {
			meterData.setUploadStatus(1); //系统修正(异常抄收)
		} else {
			meterData.setUploadStatus(0); //正常抄收
		}
		return meterData;
	}
	
	/**
	 * 将XML数据节点解码为对应的热量表数据
	 * @param distributorElement
	 * @return
	 * @throws ParseException
	 * @author Xiaopeng
	 * @date 2014-3-13
	 */
	private static IHeatMeterData24Gather parseHeatMeterData(Element distributorElement) throws ParseException {
		IHeatMeterData24Gather meterData = new IHeatMeterData24Gather();
		//数据是否需要修正
		boolean ifDataRevised = false;
		//热量表表号
		String meterNo = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "addr");
		meterData.setMeterNo(meterNo);
		//累积热量
		String sumHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "getAccount_day_heat");
		double sumHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(sumHeatStr)) {
			sumHeat = HeatMeterDataProtocolDecipher.decodeSumHeat(sumHeatStr);
		} else {
			sumHeat = new Double(FrameEntityConstants.sysrevisable_hm_sumHeat_val);
			ifDataRevised = true;
		}
		meterData.setSumHeat(sumHeat);
		//累积热量单位
		String sumHeatUnitStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "getAccount_day_heat_unit");
		Integer sumHeatUnit = 2; //默认热量单位为KWh
		if(MeasureUnitConstants.frameCode_heatUnit_kWh.equals(sumHeatUnitStr)) {
			sumHeatUnit = 2;
		}
		if(MeasureUnitConstants.frameCode_heatUnit_MWh.equals(sumHeatUnitStr)) {
			sumHeatUnit = 1;
		}
		if(MeasureUnitConstants.frameCode_heatUnit_GJ.equals(sumHeatUnitStr)) {
			sumHeatUnit = 3;
		}
		meterData.setSumHeatUnit(sumHeatUnit);
		//结算日热量
		String settleAccountHeatStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "curHot");
		double settleAccountHeat = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(settleAccountHeatStr)) {
			settleAccountHeat = HeatMeterDataProtocolDecipher.decodeSettleAccountHeat(settleAccountHeatStr);
		} else {
			settleAccountHeat = new Double(FrameEntityConstants.sysrevisable_hm_settleAccountHeat_val);
			ifDataRevised = true;
		}
		meterData.setSettleAccountHeat(settleAccountHeat);
		//结算日热量单位
		String settleAccountHeatUnitStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "curHot_unit");
		Integer settleAccountHeatUnit = 2; //默认热量单位为KWh
		if(MeasureUnitConstants.frameCode_heatUnit_kWh.equals(settleAccountHeatUnitStr)) {
			settleAccountHeatUnit = 2;
		}
		if(MeasureUnitConstants.frameCode_heatUnit_MWh.equals(settleAccountHeatUnitStr)) {
			settleAccountHeatUnit = 1;
		}
		if(MeasureUnitConstants.frameCode_heatUnit_GJ.equals(settleAccountHeatUnitStr)) {
			settleAccountHeatUnit = 3;
		}
		meterData.setSettleAccountHeatUnit(settleAccountHeatUnit);
		//热功率
		String heatPowerStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "hot_power");
		double heatPower = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(heatPowerStr)) {
			heatPower = HeatMeterDataProtocolDecipher.decodeHeatPower(heatPowerStr);
		} else {
			heatPower = new Double(FrameEntityConstants.sysrevisable_hm_heatPower_val);
			ifDataRevised = true;
		}
		meterData.setHeatPower(heatPower);
		//热功率单位
		String heatPowerUnitStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "hot_power_unit");
		Integer heatPowerUnit = 2; //默认热量单位为KW
		if(MeasureUnitConstants.frameCode_heatPowerUnit_kW.equals(heatPowerUnitStr)) {
			heatPowerUnit = 2;
		}
		if(MeasureUnitConstants.frameCode_heatPowerUnit_MW.equals(heatPowerUnitStr)) {
			heatPowerUnit = 1;
		}
		meterData.setHeatPowerUnit(heatPowerUnit);
		//瞬时流量
		String instantFlowStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "instant_flow");
		double instantFlow = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(instantFlowStr)) {
			instantFlow = HeatMeterDataProtocolDecipher.decodeInstantFlow(instantFlowStr);
		} else {
			instantFlow = new Double(FrameEntityConstants.sysrevisable_hm_instantFlow_val);
			ifDataRevised = true;
		}
		meterData.setInstantFlow(instantFlow);
		//瞬时流量单位
		String instantFlowUnitStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "instant_flow_unit");
		Integer instantFlowUnit = 1; //默认瞬时流量单位为m3/h
		if(MeasureUnitConstants.frameCode_flowPowerUnit_cubicMeter_per_hour.equals(instantFlowUnitStr)) {
			instantFlowUnit = 1;
		}
		if(MeasureUnitConstants.frameCode_flowPowerUnit_L_per_hour.equals(instantFlowUnitStr)) {
			instantFlowUnit = 2;
		}
		meterData.setInstantFlowUnit(instantFlowUnit);
		//累积流量
		String sumFlowStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "total_flow");
		double sumFlow = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(sumFlowStr)) {
			sumFlow = HeatMeterDataProtocolDecipher.decodeSumFlow(sumFlowStr);
		} else {
			sumFlow = new Double(FrameEntityConstants.sysrevisable_hm_sumFlow_val);
			ifDataRevised = true;
		}
		meterData.setSumFlow(sumFlow);
		//累积流量单位
		String sumFlowUnitStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "total_flow_unit");
		Integer sumFlowUnit = 1; //默认累计流量单位为m3
		if(MeasureUnitConstants.frameCode_flowUnit_cubicMeter.equals(sumFlowUnitStr)) {
			sumFlowUnit = 1;
		}
		if(MeasureUnitConstants.frameCode_flowUnit_L.equals(sumFlowUnitStr)) {
			sumFlowUnit = 2;
		}
		meterData.setSumFlowUnit(sumFlowUnit);
		//供水温度
		String supplyTemperatureStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "water_temperature");
		double supplyTemperature = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(supplyTemperatureStr)) {
			supplyTemperature = HeatMeterDataProtocolDecipher.decodeSupplyTemperature(supplyTemperatureStr);
		} else {
			supplyTemperature = new Double(FrameEntityConstants.sysrevisable_hm_supplyTemperature_val);
			ifDataRevised = true;
		}
		meterData.setSupplyTemperature(supplyTemperature);
		//回水温度
		String backTemperatureStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "return_water_temperature");
		double backTemperature = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(backTemperatureStr)) {
			backTemperature = HeatMeterDataProtocolDecipher.decodeBackTemperature(backTemperatureStr);
		} else {
			backTemperature = new Double(FrameEntityConstants.sysrevisable_hm_backTemperature_val);
			ifDataRevised = true;
		}
		meterData.setBackTemperature(backTemperature);
		//累积运行时间
		String runHoursStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "total_work_date");
		double runHours = 0;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(runHoursStr)) {
			runHours = HeatMeterDataProtocolDecipher.decodeRunHours(runHoursStr);
		} else {
			runHours = new Double(FrameEntityConstants.sysrevisable_hm_runHours_val);
			ifDataRevised = true;
		}
		meterData.setRunHours(runHours);
		//状态位
		String stateMark = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "status");
		//数据校验修正
		if(!StringUtils.isFullNumbericChar(stateMark)) {
			stateMark = FrameEntityConstants.sysrevisable_hm_stateMark_val;
			ifDataRevised = true;
		}
		meterData.setWrongInfo(stateMark);
		//抄表时间
		String recordTimeStr = Dom4jXmlReader.getChildElementTextByTagName(distributorElement, "record_date");
		Date recordTime = null;
		//数据校验修正
		if(StringUtils.isFullNumbericChar(recordTimeStr)) {
			recordTime = CalendarUtils.parseStringToDate(recordTimeStr, "yyMMddHHmmss");
		} else {
			recordTime = CalendarUtils.parseStringToDate(FrameEntityConstants.sysrevisable_hm_recordTime_val, "yyMMddHHmmss");
			ifDataRevised = true;
		}
		meterData.setRecordTime(recordTime);
		//设置数据类型：掌机上传数据
		meterData.setDataType(3);
		//热表数据抄收状态
		if(ifDataRevised) {
			meterData.setUploadStatus(1); //系统修正(异常抄收)
		} else {
			meterData.setUploadStatus(0); //正常抄收
		}
		return meterData;
	}

	private static ITemperaturePointDataGather parseTemperaturePointData(Element distributorElement,String  concentratorNo) throws ParseException{
		Iterator elementIterator = distributorElement.elementIterator();
		StringBuilder  parseTemp =  new StringBuilder();
		boolean ifAdd = false;
		String seriousNo = "";
		String recordTime = null;
		while(elementIterator.hasNext()) {
			 Element next = (Element) elementIterator.next();
			 String name = next.getName();
			 if("id".equals(name)) seriousNo = next.getText(); 
			 if("frTmp".equals(name)) { ifAdd = true;}
			 if("sendTime".equals(name)) {
				 recordTime = next.getText();
				 break; 
			 }
			 if(ifAdd) {
				 parseTemp.append(next.getText());
			 }
		}
				DateFormat format = new SimpleDateFormat("yyMMddHHmmss");
				ITemperaturePointDataGather dataGather = ParseUtils.toTemperaturePointDataGather(parseTemp);
				dataGather.setSeriousNum(seriousNo);//设置序列号
				dataGather.setConcentratorNo(concentratorNo);
				dataGather.setDataType(1);//设置数据类型
				dataGather.setUploadStatus(0);//设置上传类型
				try {
					dataGather.setRecordTime(format.parse(recordTime));//设置记录时间
				} catch (Exception e) {
				}
		return dataGather;
	}
	
}
